/* 1videoConference -- An open source video conferencing platform.
* Copyright (C) 2007 - 2008, Adiance Technologies Pvt. Ltd.
*
* Hardik Sanghvi <hardik.sanghvi @adiance.com>
*
* See http://www.1videoconference.org for more information about
* the 1videoConference project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, forums and mailing lists
* for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
********************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.Reflection;
using Adiance.VMukti.DAL;
using System.Windows;

namespace Adiance.VMukti.BAL
{
    public class CliLoginStatus
    {
        NetPeerService.NetPeerClient npcLoginStatus = null;
        object objLoginClass = new LoginClass();
        IsvcLoginStatusChannel svcLoginStatus;

        System.Threading.Thread servClient;

        string ServerIPAddr = "";
        bool IsHostLoggedIn = false;

        public CliLoginStatus(string MainServiceURI)
        {
            ServerIPAddr = MainServiceURI.Replace("net.tcp://", "").Split(':')[0];
            servClient = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(RegClient));
            try
            {
                servClient.Start(MainServiceURI);
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "Adiance.VMukti.VCServer--:--CliLoginStatus.cs--:--CliLoginStatus()--:--");
                Adiance.VMukti.BAL.clsUtility.LogException = exp;
                //MessageBox.Show(exp.Message);
            }
        }

        void RegClient(object MainServiceURI)
        {
            try
            {
                ((LoginClass)objLoginClass).EntsvcJoin += new LoginClass.DelsvcJoin(CliLoginStatus_EntsvcJoin);
                ((LoginClass)objLoginClass).EntsvcDoLogin += new LoginClass.DelsvcDoLogin(CliLoginStatus_EntsvcDoLogin);

                npcLoginStatus = new NetPeerService.NetPeerClient();
                svcLoginStatus = (IsvcLoginStatusChannel)npcLoginStatus.OpenClient<IsvcLoginStatusChannel>(MainServiceURI.ToString(), "LoginStatusMesh", ref objLoginClass);
                svcLoginStatus.svcJoin("Server");
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "Adiance.VMukti.VCServer--:--CliLoginStatus.cs--:--RegClient()--:--");
                Adiance.VMukti.BAL.clsUtility.LogException = exp;
                //clsException.LogError(exp);
                //MessageBox.Show(exp.Message);
            }
        }

        void CliLoginStatus_EntsvcJoin(string Role)
        {
            try
            {
                if (Role == "Host")
                {
                    IsHostLoggedIn = true;
                }
                else if (Role == "LogOut")
                {
                    IsHostLoggedIn = false;
                }
                if (IsHostLoggedIn)
                {
                    svcLoginStatus.svcDoLogin();
                }
            }
            catch (Exception exp)
            {
                exp.Data.Add("My Key", "Adiance.VMukti.VCServer--:--CliLoginStatus.cs--:--CliLoginStatus_EntsvcJoin()--:--");
                Adiance.VMukti.BAL.clsUtility.LogException = exp;
                //MessageBox.Show("CliLoginstatus_entsvcjoin : "+exp.Message);
            }
        }

        void CliLoginStatus_EntsvcDoLogin()
        {

        }

    }

}
